package com.ruoyi.user.utils;

import com.ruoyi.user.enums.BizCodeEnum;
import com.ruoyi.user.enums.ReqHandleExceptionEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author Lu.F
 * @version 1.0
 * @date 2022/11/8 22:09
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class JsonData {

    /**
     * 响应码
     */
    private int code;

    /**
     * 响应数据
     */
    private Object data;

    /**
     * 提示信息
     */
    private String msg;

    public static JsonData buildSuccess(Object data){
        return new JsonData(0,data,null);
    }

    public static JsonData buildSuccess(){
        return new JsonData(0,null,"请求成功");
    }

    public static JsonData buildError(String msg){
        return new JsonData(-1,null,msg);
    }

    public static JsonData buildError(BizCodeEnum bizCodeEnum){
        return new JsonData(bizCodeEnum.getCode(), null, bizCodeEnum.getMsg());
    }

    public static JsonData buildError(ReqHandleExceptionEnum reqHandleExceptionEnum){
        return new JsonData(reqHandleExceptionEnum.getCode(), null, reqHandleExceptionEnum.getDesc());
    }
}
